<!DOCTYPE html	PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml" xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:h="http://java.sun.com/jsf/html" xmlns:f="http://java.sun.com/jsf/core"
	xmlns:p="http://primefaces.org/ui" template="/template/template_dialog_inner_48_lrt.xhtml"
	xmlns:s="http://sduept.security.el/func">
	<ui:define name="head">
		<style>
		.ui-button, .ui-button span, button.ui-button.ui-state-default span, .ui-button.ui-state-default span
			{
			font-weight: normal
		}
		
		#createform .ui-fileupload-content, #editForm .ui-fileupload-content {
			display: none;
		}
		
		#createform .ui-fileupload-buttonbar, #editForm .ui-fileupload-buttonbar {
			background: white;
			border: none;
		}
		
		/* .ui-panelgrid {width:100%}	 */	
				
		.col-md-6 {
		    position: relative;
		    min-height: 1px;
		    padding-right: 0px;
		    padding-left: 13px;
		    margin-top:-13px;
		}
		.inspectionStationTree {
			width: 500px;
		    position: relative;
		    height: 500px;
		    overflow-y: scroll;
		}
		/* iframe {
			height:640px !important;
		} */
		</style>
		<link rel="stylesheet" href="/resources/plugins/datatables/dataTables.bootstrap.css" />		
		
		<title>#{addAssessmentPlanController.title}</title>
		<script>
		var addStationIndex;
		function openAddInspectionStationSelectorDialog() {
			
			var startTime = document.getElementById("form2:startTime").value;
			var endTime = document.getElementById("form2:endTime").value;
			var dates = [startTime,endTime];
			var planId = document.getElementById("form1:planId").value;
			var inspectionType = "InspectionSelf";
			var src = "/ui/equipmentAssessment/assessmentplan/dialog/inspectionStation_selector_stepbystep.xhtml?inspectionType="+inspectionType +"&amp;planId="+planId + "&amp;dates"+dates + "&amp;stationIds"+null;
			
			
			addStationIndex = layer.open({
				type : 2,
				area : [ '80%', '95%' ],
				fixed : false, //不固定
				title : '添加互查项',
				maxmin : true,
				content : src,
			});
		}

		// 选择模板
		function openSelectFromTemplate() {
			
			var startTime = document.getElementById("form2:startTime").value;
			var endTime = document.getElementById("form2:endTime").value;
			var dates = [startTime,endTime];
			var planId = document.getElementById("form1:planId").value;
			var inspectionType = "InspectionSelf";
			var src = "/ui/equipmentAssessment/assessmentplan/dialog/selectFromTemplateDialog.xhtml?inspectionType="+inspectionType +"&amp;planId="+planId + "&amp;dates"+dates;
			
			layer.open({
				type : 2,
				area : [ '80%', '95%' ],
				fixed : false, //不固定
				title : '选择模板',
				maxmin : true,
				content : src,
			});
		}
		
		</script>
		
	</ui:define>
	<ui:define name="top-box-tools">
		<h:form id="form1">
			<p:confirmDialog global="true" showEffect="fade" hideEffect="fade">
				<p:commandButton value="是" type="button" styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
				<p:commandButton value="否" type="button" styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
			</p:confirmDialog>
			<p:dialog widgetVar="statusDialog" modal="true" draggable="false" closable="false" resizable="false" showHeader="false">
		   		 <h:panelGrid columns="2" cellpadding="2">
		   		  <p:outputLabel  value="提示"></p:outputLabel>
		   		  <p:outputLabel value=""></p:outputLabel>
		   		  <p:outputLabel value="本次生成数据较多请稍后..."></p:outputLabel>
		   		 <!-- <p:graphicImage url="/resources/img/ico_loading2.gif" /> -->
		   		</h:panelGrid>
			</p:dialog>
			<!-- <p:dialog widgetVar="progressBarDialog" modal="true" draggable="false" closable="false" resizable="false" showHeader="false" width="300px">
				<p:progressBar widgetVar="saveProgressBar" ajax="true" value="#{addAssessmentPlanController.progress}" labelTemplate="{value}%" styleClass="animated" global="false">
			        <p:ajax event="complete"  />
			    </p:progressBar>
			</p:dialog> -->
			
			<h:inputHidden id="planId" value="#{addAssessmentPlanController.plan.id}" />
			<p:growl id="msgs" showDetail="true" />
				<p:toolbar id="btnBar">
					<f:facet name="left">
						<p:commandButton style="margin-left:5px" icon="fa fa-floppy-o"  oncomplete="PF('statusDialog').hide();"
							onstart="PF('statusDialog').show();"  update=""
							actionListener="#{addAssessmentPlanController.saveAssessmentPlan()}" value="保存草稿">
							<p:confirm header="提示" message="确定保存为草稿吗?" icon="ui-icon-alert" />
						</p:commandButton>
						<!-- <p:commandButton value="添加评价厂站" style="margin-left:5px" icon="fa fa-plus"
							actionListener="#{addAssessmentPlanController.openAddInspectionStationSelectorDialog}" >
							<p:ajax event="dialogReturn" listener="#{addAssessmentPlanController.onInspectionStationChosen}" update="treeForm:tree"/>
						</p:commandButton> -->
						<p:commandButton value="添加评价厂站" style="margin-left:5px" icon="fa fa-plus"
							onclick="openAddInspectionStationSelectorDialog()" />
						<p:commandButton value="选择模板" style="margin-left:5px" icon="fa fa-file-o"
							onclick="openSelectFromTemplate()" />
						<!-- <p:commandButton value="选择模板" style="margin-left:5px" icon="fa fa-file-o"
							actionListener="#{addAssessmentPlanController.openSelectFromTemplate()}" >
							<p:ajax event="dialogReturn" listener="#{addAssessmentPlanController.onInspectionStationChosenFromTemplate}" update="treeForm:tree"/>
						</p:commandButton> -->
						<!-- <p:commandButton style="margin-left:5px"  icon="fa fa-refresh" update="form2:baseinfo treeForm:tree"
							actionListener="#{addAssessmentPlanController.clearData()}" value="重置">
						 	<p:confirm header="提示" message="确定重置吗?" icon="ui-icon-alert" />
						</p:commandButton> -->
					</f:facet>
					<!-- <f:facet name="right">
						<p:commandButton style="margin-left:5px"  icon="fa fa-ban"
							actionListener="#{addAssessmentPlanController.cancel()}" value="关闭">
						 	<p:confirm header="提示" message="确定退出？" icon="ui-icon-alert" disabled="#{addAssessmentPlanController.isConfirm()}"/>
						</p:commandButton>
					</f:facet> -->
				</p:toolbar>
				
		</h:form>
	</ui:define>	
	
	<ui:define name="left-box-title">
		基本信息
	</ui:define>
	
	<ui:define name="left-box-body">
		<h:form id="form2">
			<p:panelGrid  id="baseinfo" cellpadding="2">	
					<p:row>
						<p:column style="font-weight: bold;">
							<p:outputLabel for="planName" value="名称：" />
						</p:column>
						<p:column >
						 <p:inputText required="true" requiredMessage="名称不能为空" id="planName"  value="#{addAssessmentPlanController.plan.name}" >					
						 	<p:ajax event="keyup" update="treeForm:tree" />
						 </p:inputText>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="font-weight: bold;">
							<p:outputLabel for="type" value="评价类型：" />
						</p:column>
						<p:column >
							<p:selectOneRadio id="type" value="#{addAssessmentPlanController.inspectionType}" unselectable="true" required="true" 
								><!-- onchange="openAlertDialog()" -->
					            <f:selectItem itemLabel="自查" itemValue="InspectionSelf" />
					            <f:selectItem itemLabel="互查" itemValue="InspectionOther" />
					            <p:ajax event="change" listener="#{addAssessmentPlanController.handleTypeChange()}" />
					        </p:selectOneRadio>
						</p:column>
					</p:row>
					<p:row>
						<p:column style="font-weight: bold;">
							<h:outputText value="评价日期：" />
						</p:column>
						<p:column>
							 <p:calendar  requiredMessage="开始时间不能为空" required="true" id="startTime"
								value="#{addAssessmentPlanController.plan.startTime}"
								pattern="yyyy-MM-dd" >
								<p:ajax event="dateSelect" listener="#{addAssessmentPlanController.handleStartTime}" update="startTime form1:msgs"/>
							</p:calendar>至<p:calendar requiredMessage="结束时间不能为空" required="true" id="endTime"
								value="#{addAssessmentPlanController.plan.endTime}"
								pattern="yyyy-MM-dd">
								<p:ajax event="dateSelect" listener="#{addAssessmentPlanController.handleEndTime}" update="endTime form1:msgs"/>
							</p:calendar> 
						</p:column> 
					</p:row>
					<p:row>
						<p:column style="font-weight: bold;">
							<p:outputLabel for="responsible" value="责任人：" />
						</p:column>
						<p:column>
							<h:inputText disabled="true" id="responsible" value="#{addAssessmentPlanController.plan.responsible}" required="true"/>
							<p:commandButton value="选择" icon="ui-icon-extlink" style="font-size:12px"
								oncomplete="PF('responsibleSelectorDialog').show()">
							</p:commandButton>
						</p:column>
					</p:row>						
					<!-- <p:row>
						<p:column style="font-weight: bold;">
							<h:outputText style="color:blue" value="模板选择（可选）：" />
						</p:column>
						<p:column>
						<p:selectOneMenu value="#{addAssessmentPlanController.templetId}">
							<f:selectItem itemLabel=""/>
							<f:selectItems value="#{addAssessmentPlanController.templateList}" var="temp" itemLabel="#{temp.name}" itemValue="#{temp.id}"/>
							<p:ajax event="itemSelect" update="treeForm:tree" 
								listener="#{addAssessmentPlanController.handleTempletSelect}"/>
						</p:selectOneMenu>
						
						<p:commandButton icon="fa fa-bandcamp" onclick="MyModal.showModal('/ui/common/assessmentTemplate_detail_lookup.xhtml?templateId=#{addAssessmentPlanController.templetName}',1300,800,'模板详情')" />
						</p:column>
						
					</p:row> -->
					
			</p:panelGrid>
		</h:form>
	</ui:define>
	
	<ui:define name="right-box-title">
		详细信息
	</ui:define>
	<ui:define name="right-box-body">
		<h:form id="treeForm">
			<p:toolbar id="treeBtn">
				<f:facet name="left">
				<p:commandButton value="删除" icon="fa fa-trash-o" process="@this" style="font-size:10px;margin-left:2px" update="treeForm:tree treeBtn form1:msgs"
					disabled="#{addAssessmentPlanController.selectedNode==null}"
					actionListener="#{addAssessmentPlanController.deleteSelectedInspectionStation}">
					<p:confirm header="提示" message="确定删除该评价项吗?" icon="ui-icon-alert" />
				</p:commandButton> 
				
				<!-- <span class="ui-separator">
	                <span class="ui-icon ui-icon-grip-dotted-vertical" />
	            </span> -->
	            <!-- <p:commandButton value="编辑评价标准" icon="fa fa-pencil" style="font-size:10px;margin-left:2px" update=""
					disabled="#{addAssessmentPlanController.selectedInspectionStation==null}"
					actionListener="#{addAssessmentPlanController.openStandardSelectorDialog()}">
					<p:ajax event="dialogReturn" update="" listener="#{addAssessmentPlanController.onStandardsChosenWhenEdit}" />
				</p:commandButton>
				<p:commandButton value="选择专家" icon="ui-icon-extlink" style="font-size:10px;margin-left:2px" 
					disabled="#{addAssessmentPlanController.selectedInspectionStation==null}"
					actionListener="#{addAssessmentPlanController.openExpertSelectorDialog}">
					<p:ajax event="dialogReturn" listener="#{addAssessmentPlanController.onExpertsChosen}" update="treeForm:tree"/>
				</p:commandButton> -->	
				<p:commandButton value="编辑" icon="fa fa-pencil" style="font-size:10px;margin-left:2px"
					disabled="#{addAssessmentPlanController.selectedInspectionStation==null}"
					oncomplete="PF('editInspectionStation').show()">
				</p:commandButton>					
				
				</f:facet>
			</p:toolbar>
			<p:panel style="border:0;width:98%">
				<p:tree value="#{addAssessmentPlanController.inspectionStationsRoot}" var="node"
					dynamic="true" id="tree" widgetVar="tree" animate="true" class="inspectionStationTree"
					selectionMode="single" style="border:0">
					<p:ajax event="select" listener="#{addAssessmentPlanController.onNodeSelect}"
						update="treeForm:treeBtn editInspectionStationForm" />
					<p:treeNode type="inspectionPlan" icon="fa fa-file-word-o">
						<h:outputText value="#{node}" />
					</p:treeNode>
					<p:treeNode type="department" icon="fa fa-home">
						<h:outputText value="#{node}" />
					</p:treeNode>
					<p:treeNode type="inspectionStation" icon="fa fa-file-text-o">
						<h:outputText value="#{node}" />
						<h:outputText style="color:#{addAssessmentPlanController.expertListColor}" value="（#{addAssessmentPlanController.getExpertListStr(node)}）" />
					</p:treeNode>
				</p:tree>
			</p:panel>
		</h:form>
		<!-- 编辑评价站 -->
		<h:form id="editInspectionStationForm">
			<p:dialog id="editInspectionStation" widgetVar="editInspectionStation" header="编辑评价厂站" width="510px" height="300px">
				<p:toolbar>
					<f:facet name="left">
						<p:commandButton value="确定" oncomplete="PF('editInspectionStation').hide()"  
							actionListener="#{addAssessmentPlanController.saveInspectionStationEdit}" 
							update="form1:msgs treeForm:tree treeForm:treeBtn" />
					</f:facet>
				</p:toolbar>
				<p:panelGrid style="text-align:center;width:95%;margin:10px">
					<p:row>
						<p:column>
							<h:outputText value="评价对象" />
						</p:column>
						<p:column>
							<h:outputText style="width:100%" value="#{addAssessmentPlanController.selectedInspectionStation.stationName}" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="名称" />
						</p:column>
						<p:column>
							<p:inputText style="width:100%" value="#{addAssessmentPlanController.selectedInspectionStation.name}" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="起止时间" />
						</p:column>
						<p:column>
							<p:calendar value="#{addAssessmentPlanController.selectedInspectionStation.startTime}" 
								navigator="true" pattern="yyyy-MM-dd" />至
							<p:calendar value="#{addAssessmentPlanController.selectedInspectionStation.endTime}" 
								navigator="true" pattern="yyyy-MM-dd" />
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="评价项目" />
						</p:column>
						<p:column>
							<p:commandButton value="编辑" style="margin-left:5px" update=""
								actionListener="#{addAssessmentPlanController.openStandardSelectorDialog()}" >
								<p:ajax event="dialogReturn" update="" listener="#{addAssessmentPlanController.onStandardsChosenWhenEdit}" />
							</p:commandButton>
						</p:column>
					</p:row>
					<p:row>
						<p:column>
							<h:outputText value="专家" />
						</p:column>
						<p:column colspan="3">
							<h:inputTextarea rows="3" cols="30" disabled="true" id="experts"
								requiredMessage="专家不能为空" required="true"
								value="#{addAssessmentPlanController.getExpertsStr()}" />
							<p:commandButton value="选择" icon="ui-icon-extlink"
								actionListener="#{addAssessmentPlanController.openExpertSelectorDialog}" >
								<p:ajax event="dialogReturn" listener="#{addAssessmentPlanController.onExpertsChosen}" update="treeForm:tree experts" />
							</p:commandButton>
						</p:column>
					</p:row>
				</p:panelGrid>
			</p:dialog>
		</h:form>
		<!-- 负责人选择dialog -->
		<h:form id="responsibleSelectorForm">
			<p:dialog id ="responsibleSelectorDialog" widgetVar="responsibleSelectorDialog" width="500" height="550" modal="true"  header="负责人选择">
			    <p:toolbar id="responsibleToolbar">
					<f:facet name="left">
						<p:autoComplete placeholder="输入人员首字母可查" id="orgPerson" size="18"
							value="#{addAssessmentPlanController.personName}"
							completeMethod="#{addAssessmentPlanController.completeResponsibles}"
							scrollHeight="400" style="float:left;margin-top:5px;"
							 dropdown="true">
							<p:ajax event="itemSelect" update ="responsibleSelectorForm:responsibleTree responsibleToolbar"
								listener="#{addAssessmentPlanController.autoCompleteOrgTree}" />
						</p:autoComplete>
						<p:commandButton icon="fa fa-refresh"
							style="margin-left:5px;margin-top:5px;" value="重置"
							actionListener="#{addAssessmentPlanController.refresh}" update="responsibleSelectorForm:responsibleTree responsibleSelectorForm:responsibleToolbar" />
					</f:facet>
					<f:facet name="right">
						<p:commandButton  value="确定"  style="margin-right:10px;margin-top:5px;" id="okBtn"
							actionListener="#{addAssessmentPlanController.saveResponsible}"
							update="form2:responsible"
					     	disabled="#{addAssessmentPlanController.selectedResponsible == null}"
					     	oncomplete="PF('responsibleSelectorDialog').hide()" />
					</f:facet>
				</p:toolbar>
		       <p:tree value="#{addAssessmentPlanController.responsibleSelectorRoot}" var="node"  
					id="responsibleTree" selectionMode="single"   style="border:0"   dynamic="true" 
				    animate="true"  selection="#{addAssessmentPlanController.responsibleSelectedNode}">
					<p:ajax event="expand" update="responsibleSelectorForm:responsibleTree" listener="#{addAssessmentPlanController.onResponsibleNodeExpand}" />	
					<p:ajax event="select" listener="#{addAssessmentPlanController.onResponsibleNodeSelect}"
						update="responsibleSelectorForm:responsibleToolbar"/>
					<p:treeNode type="dept" icon="fa fa-home">
						<h:outputText value="#{node}" />
					</p:treeNode>
					<p:treeNode type="personnel" icon="fa fa-user">
						<h:outputText value="#{node}" />
					</p:treeNode>
				</p:tree>
			</p:dialog>
		</h:form>
		<!-- 提示弹窗 -->
		<div id="alertDialog" style="display:none;padding:20px">
			<h:outputText value="确定继续吗？该操作将清空已有评价厂站信息！" />
			<p:panelGrid style="width:100%;margin-top:5px">
				<p:row style="border:none">
					<p:column style="border:none;float:right">
						<p:commandButton value="是" actionListener="#{addAssessmentPlanController.handleTypeChange(1)}" 
							update="form2 treeForm:tree" oncomplete="closeAlertDialog()"/>
						<p:commandButton value="否" actionListener="#{addAssessmentPlanController.handleTypeChange(0)}" 
							update="form2" oncomplete="closeAlertDialog()"/>
					</p:column>
				</p:row>
			</p:panelGrid>
		</div>
	</ui:define>
	
	<ui:define name="contentend">
		<script src="/resources/js/tables/singleScrollTable.js" />
		<script>
			function hideImg() {
				document.getElementById("editForm:image").style.display = "none";
			}
			function openAlertDialog() {
				layer.open({
					type:1,
					title: '提示',
					content: $('#alertDialog'),
					btn:false,
				});
			}
			function closeAlertDialog() {
				layer.closeAll('page');
			}
		</script>
	</ui:define>
</ui:composition>